package com.jiazhong.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servletA")
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Cookie cookie1 = new Cookie("username","zhangsan");
        Cookie cookie2 = new Cookie("password","123456");
        //设置cookie的存放时间,60s
        cookie1.setMaxAge(60);
        //设置cookie的访问路径
        cookie2.setPath("/conversation_war/servletB");
        resp.addCookie(cookie1);
        resp.addCookie(cookie2);
    }
}
